package com.sskj.gocoin.p.activity;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.sskj.common.util.MD5Util;
import com.sskj.gocoin.MyAppLication;
import com.sskj.gocoin.m.HttpConfig;
import com.sskj.gocoin.m.bean.FabiOrderBean;
import com.sskj.gocoin.m.bean.HttpData;
import com.sskj.gocoin.m.http.JsonCallBack;
import com.sskj.gocoin.p.base.BasePresenter;
import com.sskj.gocoin.utils.ToastUtil;
import com.sskj.gocoin.v.activity.FabiSellDetailActivity;


public class FabiSellDetailPresenter extends BasePresenter<FabiSellDetailActivity> {

    public void getOrderInfo(String orderNum, boolean isLoad) {

        OkGo.<HttpData<FabiOrderBean>>post(HttpConfig.BASE_URL + HttpConfig.FABI_ORDER_INFO)
                .params("order_num", orderNum)
                .execute(new JsonCallBack<HttpData<FabiOrderBean>>(this, isLoad) {
                    @Override
                    public void _onSuccess(Response<HttpData<FabiOrderBean>> response) {
                        if (response.body().getCode() == 200) {
                            mView.updateUI(response.body().getData());
                        }
                    }
                });
    }


    /**
     * 标记已付款
     *
     * @param orderNum
     */
    public void markPay(String orderNum) {
        OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.FABI_ORDER_MARK_PAY)
                .params("order_no", orderNum)
                .params("account", MyAppLication.getAccount())
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void _onSuccess(Response<HttpData> response) {
                        ToastUtil.showShort(response.body().getMsg());
                        if (response.body().getCode() == 200) {
                            getOrderInfo(orderNum, true);
                        }
                    }
                });
    }

    /**
     * 取消订单
     *
     * @param orderNum
     */
    public void cancleOrder(String orderNum) {
        OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.FABI_ORDER_CANCLE)
                .params("order_num", orderNum)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void _onSuccess(Response<HttpData> response) {
                        ToastUtil.showShort(response.body().getMsg());

                        if (response.body().getCode() == 200) {
                            getOrderInfo(orderNum, true);
                        }
                    }
                });
    }

    /**
     * 账单申诉
     *
     * @param orderNum
     */
    public void allegeOrder(String orderNum, String refer, String shop_account, String ss_type, String ss_reason) {
        OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.FABI_ORDER_ALLEGE)
                .params("order_num", orderNum)
                .params("refer", refer)
                .params("shop_account", shop_account)
                .params("ss_type", ss_type)
                .params("ss_reason", ss_reason)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void _onSuccess(Response<HttpData> response) {
                        ToastUtil.showShort(response.body().getMsg());

                        if (response.body().getCode() == 200) {
                            getOrderInfo(orderNum, true);
                        }
                    }
                });
    }

    /**
     * 确认放行
     *
     * @param orderNum
     * @param pwd
     */
    public void letGo(String orderNum, String pwd) {
        OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.FABI_ORDER_LET_GO)
                .params("order_no", orderNum)
                .params("tpwd", MD5Util.getMd5Value(pwd))
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void _onSuccess(Response<HttpData> response) {
                        ToastUtil.showShort(response.body().getMsg());

                        if (response.body().getCode() == 200) {
                            getOrderInfo(orderNum, true);
                        }
                    }
                });
    }
}
